package fun.lifepoem.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author Yiwyn
 * @create 2022/6/27 16:41
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RestResponse<T> implements Serializable {

    private static final long serialVersionUID = 1L;


    private static final int SUCESS = 200;

    private static final int FAIL = 400;


    private int code;
    private String msg;
    private T data;


    public static <T> RestResponse<T> doSuccess(String message, T data) {
        return new RestResponse<T>(SUCESS, message, data);
    }

    public static <T> RestResponse<T> doError(String message) {
        return new RestResponse<T>(FAIL, message, null);
    }


    public static <T> RestResponse<T> doError(String message, T data) {
        return new RestResponse<T>(FAIL, message, data);
    }
}
